package com.buer.storage.controller;

import com.buer.storage.commom.JsonResult;
import com.buer.storage.dto.*;
import com.buer.storage.entity.Prod;
import com.buer.storage.entity.ProdCategory;
import com.buer.storage.service.ProdCategoryService;
import com.buer.storage.vo.R;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

//装备分类管理
@RestController
@RequestMapping("/prodcategory")
public class ProdCategoryController {
    @Resource
    private ProdCategoryService prodCategoryService;

    //增加装备分类
    @PostMapping("/add.do")
    public R add(@RequestBody ProdCategoryDto prodCategoryDto) {
        if (prodCategoryService.add(prodCategoryDto) > 0) {
            return R.setR(1, "添加装备分类成功", null);
        }
        return R.setR(0, "添加装备分类失败", null);
    }

    //删除装备分类
    @GetMapping("/delete.do")
    public R delete(int categoryId) {
        if (prodCategoryService.delete(categoryId) > 0) {
            return R.setR(1, "删除装备分类成功", null);
        }
        return R.setR(0, "删除装备分类失败", null);
    }

    //修改装备分类
    @PostMapping("/update.do")
    public R update(@RequestBody ProdCategory prodCategory){
        if (prodCategoryService.update(prodCategory)>0){
            return R.setR(1,"修改装备分类成功",null);
        }
        return R.setR(0,"修改装备分类失败",null);
    }

    //查询所有装备分类
    @GetMapping("/select.do")
    public List<ProdCategory> select(){
        return prodCategoryService.select();
    }

    //通过编号或者名字查询
    @GetMapping("/selectByName")
    public JsonResult selectByName(String categoryNumber, String categoryName){
        List<ProdCategory> prodCategories = prodCategoryService.selectByName(categoryNumber,categoryName);
        return new JsonResult(1,prodCategories);
    }


    //根据仓库id查询库位信息
    @GetMapping("/selectTwo.do")
    public List<CategorySelectDto> selectTwo(){
        List<CategorySelectDto> category = prodCategoryService.SelectTwo();
        return category;
    }

    @GetMapping("/selectCategoty")
    public List<Prod> selectCategoty(Integer categoryTwoId,String prodName){
        List<Prod> prodList = prodCategoryService.selectCategory(categoryTwoId, prodName);
        return prodList;
    }
}
